using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using RTC_Importer.Data;

namespace RTC_Importer
{
    /// <summary>
    /// Parser
    /// </summary>
    public partial class Converter_RTC
    {
        private void ParseDungeonLayout(StreamReader sr)
        {
            string line = "";
            int linesAdded = 1;
            List<RTC_Level> levels = new List<RTC_Level>();
            RTC_Level level = new RTC_Level();

            while (true)
            {
                line = sr.ReadLine();

                if (line.Contains("/******************************************************************************/"))
                    return; //we are done here...

                RTC_KeyValue kv = line.To_RTC_KeyValue();

                if (kv != null)
                {
                    switch (kv.Key)
                    {
                        case "WALLSET":
                            {
                                level.WALLSET = kv.Value;
                                break;
                            }
                        case "LIGHT_AMBIENT":
                            {
                                level.LIGHT_AMBIENT = kv.Value.ToInt();
                                break;
                            }
                        case "LIGHT_MINIMUM":
                            {
                                level.LIGHT_MINIMUM = kv.Value.ToInt();
                                break;
                            }
                        case "LIGHT_MAXIMUM":
                            {
                                level.LIGHT_MAXIMUM = kv.Value.ToInt();
                                break;
                            }
                        case "OFFSET":
                            {
                                level.OFFSET = kv.Value.ToPoint();
                                break;
                            }
                        case "SIZE":
                            {
                                level.SIZE = kv.Value.ToPoint();
                                level.CreateLayout();
                                break;
                            }
                    }
                }

                if ((level.SIZE.X != 0) && (line.Length == level.SIZE.X))
                {
                    
                    for(int i = 0;i<=level.SIZE.X-1;i++)
                    {
                        level.Layout[i, linesAdded] = line[i] == '0' ? false : true;
                    }

                    linesAdded++;
                    if (linesAdded == level.SIZE.Y)
                    {
                        levels.Add(level);
                        level = new RTC_Level();
                    }
                }
            }
        }
    }
}